﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Card.Manager.Controls
{
    public partial class UserPicker : System.Web.UI.UserControl
    {
        public event PickerUser OnUserPicker;
        public delegate void PickerUser(int userID);

        public string Text
        {
            get
            {
                return ViewState["Text"] == null ? string.Empty : ViewState["Text"].ToString();
            }
            set
            {
                ViewState["Text"] = value;
            }
        }

        public bool AutoPostBack
        {
            get
            {
                return ViewState["AutoPostBack"] == null ? false : bool.Parse(ViewState["AutoPostBack"].ToString());
            }
            set
            {
                ViewState["AutoPostBack"] = value;
            }
        }
                
        public string ExcludeUserIDs
        {
            get
            {
                return ViewState["ExcludeUserIDs"] == null?string.Empty:ViewState["ExcludeUserIDs"].ToString();
            }
            set
            {
                ViewState["ExcludeUserIDs"] = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.btnQuery.Value = Text;
            this.btnQuery.Attributes.Add("onclick", this.ClientID + "Picker()");
        }

        protected void btnPicker_Click(object sender, EventArgs e)
        {
            if (OnUserPicker != null)
            {
                OnUserPicker(int.Parse(this.txtUserID.Text));
            }
        }
    }
}